package com.gxa.xiaoucomeshome.service.impl;

import com.gxa.xiaoucomeshome.pojo.Materials;
import com.gxa.xiaoucomeshome.vo.*;
import com.gxa.xiaoucomeshome.mapper.UserManagerMapper;
import com.gxa.xiaoucomeshome.pojo.Address;
import com.gxa.xiaoucomeshome.service.UserManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class UserManagerServiceImpl implements UserManagerService {
    @Autowired
    UserManagerMapper userManagerMapper;

    @Override
    public List<UserManagerVo> selectAllByPage() {
        List<UserManagerVo> userManagerVos = userManagerMapper.selectAllByPage();
        return userManagerVos;
    }
    /**
     * 模糊查询用户信息
     * @param page
     * @param size
     * @param name (包含用户姓名和手机)
     * @param state
     * @param site_id
     * @return
     */
    @Override
    public List<UserManagerVo> selectAllByNameAndPhone(Integer page, Integer size,
                                                       String name, Integer state,Integer site_id) {
        List<UserManagerVo> userManagerVos = userManagerMapper.selectAllByNameAndPhone(page,size,name,  state, site_id);

//        Integer state,Integer site_id,phone,String phone
        return userManagerVos;
    }

    @Override
    public Integer selectUserManageCount(String name, Integer state, Integer site_id) {
        Integer integer = userManagerMapper.selectUserManageCount(name, state, site_id);
        return integer;
    }

    /**
     * 查询用户基本信息
     * @param id
     * @return
     */
    @Override
    public List<UserManagerVo> selectManagerById(Integer id) {
        List<UserManagerVo> userManagerVos = userManagerMapper.selectManagerById(id);

        return userManagerVos;
    }

//    @Override
//    public Integer updateUserState(Integer id) {
//
//        Integer integer = userManagerMapper.updateUserState(id);
//        return integer;
//    }
//
//
//    @Override
//    public Integer updateOutSate(Integer id) {
//        Integer integer = userManagerMapper.updateOutState(id);
//        return integer;
//    }

    /**
     * 冻结所选用户
     * @param id
     * @return
     */
    @Override
    public Integer updateALlState(Integer id) {
        Integer integer = userManagerMapper.updateAllState(id);
        return integer;
    }
    /**
     * 解冻
     * @param id
     * @return
     */
    @Override
    public Integer updateOutALlState(Integer id) {
        Integer integer = userManagerMapper.updateOutALlState(id);
        return integer;
    }
    /**
     * 查询用户所有地址
     * @param id
     * @return
     */
    @Override
    public List<Address> selectUserAddress(Integer id) {
        List<Address> addresses = userManagerMapper.selectUserAddress(id);
        return addresses;
    }

    /**
     * 查询用户所有订单详情
     */
    @Override
    public List<UserOrderDetailVo> selectUserOrder(Integer page, Integer size, Integer id) {
        List<UserOrderDetailVo> userOrderDetailVos = userManagerMapper.selectUserOrder(page, size, id);

        return userOrderDetailVos;
    }

    @Override
    public Integer selectUserCount(Integer id) {
        Integer integer = userManagerMapper.selectUserCount(id);
        return integer;
    }

    /**
     * 昵称，收货人，收货人电话，配送员进行模糊查询用户订单详情
     * @return
     */
    @Override
    public List<UserOrderDetailVo> selectUserByNameAndPhone(Integer page, Integer size, String all,Integer state,Integer site_id,Date startdispatch_time,
                                                            Date enddispatch_time) {
        List<UserOrderDetailVo> userOrderDetailVos = userManagerMapper.selectUserByNameAndPhone(page, size, all,
                state,site_id,startdispatch_time
                ,enddispatch_time);

        return userOrderDetailVos;
    }

    @Override
    public Integer selectByNameCount(String all, Integer state, Integer site_id, Date startdispatch_time, Date enddispatch_time) {
        Integer integer = userManagerMapper.selectByNameCount(all, state, site_id, startdispatch_time, enddispatch_time);
        return integer;
    }

    @Override
    public List<UserOrderDetailVo> selectAllOrder() {
        List<UserOrderDetailVo> userOrderDetailVos = userManagerMapper.selectAllOrder();
        return userOrderDetailVos;
    }

//    @Override
//    public int deleteUserManagerByOrderId(String order_id) {
//        int i = userManagerMapper.deleteUserManagerByOrderId(order_id);
//        return i;
//    }
    /**
     * 批量删除用户订单信息
     * @param order_id
     * @return
     */
    @Override
    public int deleteUserManagerByOrderIdAll(String[] order_id) {
        int i = userManagerMapper.deleteUserManagerByOrderIdAll(order_id);
        return i;
    }

    @Override
    public int deleteUser(String order_id) {
        int i = userManagerMapper.deleteUser(order_id);
        return i;
    }

    /**
     * 查询订单详情
     * @param order_id
     * @return
     */
    @Override
    public List<UserOrderDetailUpdateVo> selectUserOrderDetailAll(String order_id) {
        List<UserOrderDetailUpdateVo> userOrderDetailUpdateVos = userManagerMapper.selectUserOrderDetailAll(order_id);

        return userOrderDetailUpdateVos;
    }
    /**
     * 查询物料详情
     * @param page
     * @param size
     * @param materials_name
     * @param site_id
     * @return
     */
    @Override
    public List<MaterialsVo> selectMaterialsAll(Integer page, Integer size, String materials_name, Integer site_id) {
        List<MaterialsVo> materialsVos = userManagerMapper.selectMaterialsAll(page, size, materials_name, site_id);

        return materialsVos;
    }

    @Override
    public Integer selectMaterialsCount(String materials_name, Integer site_id) {
        Integer integer = userManagerMapper.selectMaterialsCount(materials_name, site_id);
        return integer;
    }

    /**
     * 删除物料
     * @return
     */
    @Override
    public int deleteMaterials(Integer materials_id) {
        int i = userManagerMapper.deleteMaterials(materials_id);
        return i;
    }
    /**
     * 添加物料
     */
    @Override
    public void insertMaterials(Materials materials) {
        userManagerMapper.insertMaterials( materials.getMaterials_name(),materials.getMaterials_num(),
                materials.getMaterials_unit(),materials.getMaterials_cost(),materials.getMaterials_price(),
                materials.getSite_id());
    }
    /**
     * 修改物料信息
     * @param materials
     */
    @Override
    public void updateMaterials(Materials materials) {
        userManagerMapper.updateMaterials(materials.getMaterials_id(), materials.getMaterials_name(),materials.getMaterials_num(),
                materials.getMaterials_unit(),materials.getMaterials_cost(),materials.getMaterials_price(),
                materials.getMaterials_id());
    }

    @Override
    public List<MaterialsVo>  editMaterials(Integer materials_id) {
        List<MaterialsVo> materialsVos = userManagerMapper.editMaterials(materials_id);
        return materialsVos;
    }

    @Override
    public List<AdminRoleVo> editAdminRoleVo(Integer admin_id) {
        List<AdminRoleVo> adminRoleVos = userManagerMapper.editAdminRoleVo(admin_id);
        return adminRoleVos;
    }

    @Override
    public List<RoleVo> editRoleVo(Integer role_id) {
        List<RoleVo> roleVos = userManagerMapper.editRoleVo(role_id);
        return roleVos;
    }

}
